<?php

use yii\db\Migration;

class m170620_033905_create_headmaster extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }


    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->createTable('{{%headmaster}}',[
                'id' => $this->primaryKey()->notNull().' COMMENT \'自增id\'',
                'name' => $this->string(50)->defaultValue(null).' COMMENT \'姓名\'',
                'img' => $this->string(200)->defaultValue(null).' COMMENT \'照片\'',
                'mechanic_id' => $this->integer(11)->defaultValue(0).' COMMENT \'机构id\'',
                'description' => $this->text()->defaultValue(null).' COMMENT \'描述\'',
                'sex' => $this->smallInteger(2)->defaultValue(0).' COMMENT \'性别 0 女 1 男\'',
                'age' => $this->smallInteger(3)->defaultValue(0).' COMMENT \'年龄\'',
                'address' => $this->string(200)->defaultValue(null).' COMMENT \'地址\'',
                'mobile' => $this->string(11)->defaultValue(null).' COMMENT \'手机\'',
                'area' => $this->string(50)->defaultValue(null).' COMMENT \'地区\'',
                'status' => $this->smallInteger(2)->defaultValue(0).' COMMENT \'是否授课 0 不授课 1 授课 \'',
                'created_at' => $this->integer(11)->defaultValue(0).' COMMENT \'添加时间\'',
                'updated_at' => $this->integer(11)->defaultValue(0).' COMMENT \'修改时间\'',
                'email' => $this->string(32)->defaultValue(null).' COMMENT \'邮箱\'',
                'cate_id' => $this->smallInteger(3)->defaultValue(null).' COMMENT \'分类 1 益智 2 音乐 3 形体\'',
                'account' => $this->string(11)->defaultValue(null).' COMMENT \'账号\'',
            ]);
        }
    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach($dbs as $v){
            $this->db = $v;
            $this->dropTable('{{%headmaster}}');
        }
    }
}
